

// Wave gadget helpers...


function swapCSS( a, b, propertynamea, propertynameb ) { // FIX: replace this with something better, pass in .css() and mayeb something more interesting, although that isn't as readable on the client side...
	if( a && b && propertynamea ) {
		var sa = a.css( propertynamea );
		var sb = b.css( ( propertynameb )? propertynameb : propertynamea ); // FIX: ! tertiary pretty, or at least try running the variations at least once before removing the FIX note :)
		if( sa && sb ) {
			a.css( propertyname, sb );
			b.css( propertyname, sa );
		}
	}
}


function createElementSVG( svgtype, attributes ) {
	var retval = document.createElementNS( 'http://www.w3.org/2000/svg', svgtype ); // chain?
	setAttributesSVG( retval, attributes );
	return retval;
}


function setAttributesSVGurl( o, url ) {
	setAttributesSVG( o, {'xlink:href': url}, 'http://www.w3.org/1999/xlink' );
}


function setAttributesSVG( o, attributes, namespace ) { // FIX: swapping arg order BAD API DESIGN
	if( ! namespace ) { namespace = null; }
	for( var attribute in attributes ) { // Use comprehensions?  application/javascript;version=1.8
		o.setAttributeNS( namespace, attribute, attributes[attribute] );
	}
}


function isObjectEmpty( o ) { // FIX: is this really necessary?!
	var retval = true;
	if( o ) {
		for( var lame in o ) {
			if( lame && o.hasOwnProperty( lame ) ) {
				retval = false;
				break; // wow, that is so bogus
			}
		}
	}
	return retval;
}


function appendConditionalSpace( s ) {
	if( s ) { s += ' '; }
	return s;
}


function buildParticipantHTML( p, omitname, omitid, omitimage ) {
	var retval = '';
	if( p ) { // FIX: mixing HTML with JavaScript?!
		if( ! omitname ) {
			retval = appendConditionalSpace( retval );
			retval += p.getDisplayName();
		}
		if( ! omitid ) {
			retval = appendConditionalSpace( retval );
			retval += '(' + p.getId() + ')';
		}
		if( ! omitimage ) {
			retval = appendConditionalSpace( retval );
			retval += '<img src="' + p.getThumbnailUrl() + '" />';
		}
	}
	return retval;
}

